let res = null;
// $(".showMenu").css("display", "none");
// $("#downShow").css("display", "none");
// $(".up").css("display", "none");
$("#register_btn").click(() => {
    let options = {
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        },
    };
    let data = {
        username: $("#username").val(),
        nickname: $("#nickname").val(),
        password: $("#password").val(),
        rpassword: $("#rpassword").val(),
    };


    axios.post("http://127.0.0.1:8888/users/register", formatData(data), options)
        .then(response => {
            console.log(response.data);
            res = response.data;
            if (res.code === 0) {
                error(res);
                console.log(res);
            } else if (res.code === 1) {
                success();
                console.log(res);
            }
        })

})

function error(res) {
    console.log(res)
    alert("抱歉注册失败 : " + res.message);
    
}

function success() {
    alert("恭喜注册成功！");
    location.href = "./login.html";
    sessionStorage.setItem("usermsg",  ({
        username: username.value,
        password: password.value
    }));
    console.log(res)
}
